<template>
  <view class="unusual page--column">
    <view class="col-main u-main">
      <list-page :config="page.config" :form="page.form">
        <template v-slot="{listData}">
          <view class="u-item" v-for="(item,index) in listData" :key="index">
            <view class="title">
              <view class="sn">订单编号：{{ item.sn }}</view>
              <view class="status">{{ cancelStatus(item.status) }}</view>
            </view>
            <view class="content"
              @tap="nav(`/subpackage/order/pages/purchanse/cancel/_id?id=${item.id}&cancelType=${page.form.query.cancelType}`)">
              <view class="c-item">
                <text>商品数量</text>
                <text>{{ item.goodsItemsQuantity }}件</text>
              </view>
              <view class="c-item">
                <text>出库数量</text>
                <text>{{ item.goodsItemsQuantity-item.goodsItemsQuantityNoStockOut }}件</text>
              </view>
              <view class="c-item">
                <text>未出库数量</text>
                <text>{{ item.goodsItemsQuantityNoStockOut }}件</text>
              </view>
              <view class="c-item">
                <text>订单金额</text>
                <text>{{ item.isNewDistributor === 1 ? (item.amount + item.goodsItemsQuantity*35) : item.amount }}元</text>
              </view>
              <view class="c-item">
                <text>订单时间</text>
                <text>{{ item.purchanseCreateTime }}</text>
              </view>
              <view class="c-item">
                <text>订单类型</text>
                <text>{{ purchanseType(item.purchanseType) }}</text>
              </view>
            </view>
            <view class="button">
              <view class="order-details"
                @tap="nav(`/subpackage/order/pages/purchanse/cancel/_id?id=${item.id}&cancelType=${page.form.query.cancelType}`)">
                订单详情</view>
            </view>
          </view>
        </template>
      </list-page>
    </view>
  </view>
</template>

<script>
  import listPage from '@/components/list-page';

  export default {
    components: {
      listPage
    },
    data() {
      return {
        page: {
          config: {
            entity: 'Approval',
            action: 'page',
            enablePull: true
          },
          form: {
            query: {
              typeId: 8,
              cancelType: 1
            }
          }
        }
      }
    },
    onLoad(options) {
      this.page.form.query.cancelType = Number(options.type);
      this.setNavigationBarTitle(Number(options.type));
    },
    methods: {
      setNavigationBarTitle(type) {
        if (type === 1) {
          this.setNavTitle('异常订单');
        } else {
          this.setNavTitle('废弃订单');
        }
      }
    }
  };
</script>

<style lang="less">
  page {
    background-color: #f7f7f7;

    .unusual {
      display: flex;
      flex-direction: column;
      align-items: center;

      .u-main {
        width: 100%;
        height: 100vh;

        .u-item {
          width: 660rpx;
          margin-top: 30rpx;
          margin-left: 25rpx;
          margin-right: 25rpx;
          padding: 20rpx;
          background: #ffffff;
          border-radius: 20rpx;

          .title {
            height: 40rpx;
            margin-bottom: 55rpx;
            display: flex;
            justify-content: space-between;
            font-size: 32rpx;

            .sn {
              width: 500rpx;
              border-left: 8rpx solid #d61e85;
              padding-left: 10rpx;
              word-break: break-all;
              font-weight: bold;
            }

            .status {
              color: #db187c;
            }
          }

          .content {
            margin-bottom: 15rpx;
            border-bottom: 1rpx solid #f4f4f4;
            font-size: 30rpx;

            .c-item {
              height: 50rpx;
              margin-bottom: 35rpx;
              display: flex;
              justify-content: space-between;
              color: #666666;
            }
          }

          .button {
            height: 55rpx;
            display: flex;
            justify-content: flex-end;

            .order-details {
              width: 160rpx;
              height: 55rpx;
              margin-left: 15rpx;
              background: #ffffff;
              border-radius: 30rpx;
              font-size: 30rpx;
              text-align: center;
              line-height: 55rpx;
              border: 1rpx solid #db187c;
              color: #db187c;
            }
          }
        }
      }
    }
  }
</style>